<template>
  <div v-if="state" class="info">
      <!-- <el-button v-if="som" type="primary" @click="addInfo">添加客服</el-button> -->
      <el-table v-if="som"
        :data="this.tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
        style="width: 100%">
        <el-table-column
        label="客服id"
        prop="id">
        </el-table-column>
        <el-table-column
        label="客服姓名"
        prop="name">
        </el-table-column>
        <el-table-column
        label="登录ip"
        prop="ip">  
        </el-table-column>
        <el-table-column
        label="登录时间"
        prop="time">  
        </el-table-column>
        <el-table-column
        align="right">
        <template slot-scope="scope">
            <el-button
            size="mini"
            type="warning"
            @click="handleFind(scope.$index, scope.row)">查看</el-button>
            <!-- <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button> -->
        </template>
        </el-table-column>
    </el-table>

    <el-pagination v-if="som"
      class="fenye"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-size="10"
      layout="prev, pager, next, jumper"
      :total="100">
    </el-pagination>


    <router-view />
  </div>
  <div v-else>
      功能开发中......
  </div>
</template>

<script>
import {mapState} from 'vuex'
  export default {
    data() {
      return {
        //state:控制显示，年后开发
        state:false,
        som : true,
        search: '',
        currentPage: 1
      }
    },
    computed:{
        ...mapState({
            tableData:state => state.info.service
        })
    },
    methods: {
        // ...mapMutations({
        //    delete:'info/delete' 
        // }),
        // handleEdit(index, row) {
        //     this.$router.push({ path: `/info/add`, query: row})
        // },
        handleFind(index, row){
            this.$router.push({path:'/info/find',query:{id:row.id}})
        },
        handleCurrentChange() {
        }
        // addInfo() {
        //     this.$router.push({path: '/info/add'})
        // },
        // handleDelete(index, row) {
        //     this.$confirm(`确定删除客服${ row.name }，是否继续？`,'提示',{
        //         confirmButtonText: '确定',
        //         cancelButtonText: '取消',
        //         type: 'warning'
        //     }).then(() => {
        //         this.$message({
        //             type:'success',
        //             message:'删除成功'
        //         });
        //         this.delete(row);
        //     }).catch( () => {
        //         this.$message({
        //             type:'info',
        //             message:'已取消删除'
        //         });
        //     })
        // }
    },
    // 路由守卫判断 是否进入详情页,隐藏添加客服按钮
    beforeRouteUpdate(to, from, next){
        if((to.path !== '/info')&&(from.path === '/info')){
            this.som = false;
        }else{
            this.som = true;
        }
        next();
    },
    //不是详情页刷新页面，隐藏添加客服按钮
    mounted(){
        if(this.$route.path !== '/info'){
            this.som = false;
        }
    }
  }
</script>
<style lang="scss" scoped>
.info{
    width: 100%;
    background: #fff;
    box-sizing: border-box;
}
</style>
